<?php $this->setPreconfiguredValue(); ?>
<?php $_product = $this->getProduct(); ?>
<?php $_associatedProducts = $this->getAssociatedProducts(); ?>
<?php $_hasAssociatedProducts = count($_associatedProducts) > 0; ?>
<div class="wrap-sc">
<?php if ($_product->isAvailable()): ?>
    <span class="in-stock"><?php echo $this->__('In stock') ?></span>
<?php else: ?>
    <span class="out-of-stock"><?php echo $this->__('Out of stock') ?></span>
<?php endif; ?>
	<span  class="t-sc"><?php echo $this->__("Product code:"); ?></span>
	<span class="pro-code"><?php echo $_product->getSku(); ?></span>
</div>
<?php echo $this->getChildHtml('product_type_data_extra') ?>
<table class="data-table grouped-items-table" id="super-product-table">
    <thead>
        <tr>
            <th><?php echo $this->__('Product Name') ?></th>
            <?php if ($this->getCanShowProductPrice($_product)): ?>
            <th class="a-right"><?php echo $this->__('Price') ?></th>
            <?php endif; ?>
            <?php if ($_product->isSaleable()): ?>
            <th class="a-center"><?php echo $this->__('Qty') ?></th>
            <?php endif; ?>
        </tr>
    </thead>
    <tbody>
    <?php if ($_hasAssociatedProducts): ?>
    <?php foreach ($_associatedProducts as $_item): 
			$qty = (int)$_item->getQty();	
			$id = $_item->getId();
			$_product = Mage::getModel('catalog/product')->load($id);
			$max_sale_qty = $_product->getStockItem()->getMaxSaleQty();
			$min_sale_qty = $_product->getStockItem()->getMinSaleQty();
			$qtyStock   = (int)Mage::getModel('cataloginventory/stock_item')->loadByProduct($_product)->getQty();
			
			if($qty != 0){			
				$temp0 = $max_sale_qty - $qty;
				$temp1 = $qtyStock - $qty;
				$temp2 = $qty - $min_sale_qty;
				if($temp0 < 0 || $temp1 < 0 || $temp2 < 0){
					$temp = 1;
				}
			}else{
				$temp = 0;
			}		
	?>
        <?php $_finalPriceInclTax = $this->helper('tax')->getPrice($_item, $_item->getFinalPrice(), true) ?>
        <tr>
            <td><?php echo $this->escapeHtml($_item->getName()) ?></td>
            <?php if ($this->getCanShowProductPrice($_product)): ?>
            <td class="a-right">
                <?php if ($this->getCanShowProductPrice($_item)): ?>
                <?php echo $this->getPriceHtml($_item, true) ?>
                <?php echo $this->getTierPriceHtml($_item) ?>
                <?php endif; ?>
            </td>
            <?php endif; ?>
            <?php // if ($_product->isSaleable()): ?>
            <td class="a-center">
            <?php if ($_item->isSaleable() && $qty >= 0) : ?>
                <input type="text" id="qty<?php echo $_item->getId() ?>" name="super_group[<?php echo $_item->getId() ?>]"  value="<?php echo $_item->getQty()*1 ?>" title="<?php echo $this->__('Qty') ?>" class="grounped-pro input-text qty" />
				<input type="hidden" id="min_qty_stock<?php echo $_item->getId() ?>" name="min_qty_stock" value="<?php echo $min_sale_qty;?>"/>						
				<input type="hidden" id="max_qty_stock<?php echo $_item->getId() ?>" name="max_qty_stock" value="<?php echo $max_sale_qty; ?>"/>
				<input type="hidden" id="qty_stock<?php echo $_item->getId() ?>" name="qty_stock" value="<?php echo $qtyStock; ?>"/>
				<input type="hidden" id="cur_pro_name<?php echo $_item->getId() ?>" name="cur_pro_name" value="<?php echo $this->escapeHtml($_item->getName()); ?>"/>
				<input type="hidden" id="re<?php echo $_item->getId() ?>" name="re<?php echo $_item->getId() ?>" class="re" value="<?php if($temp==1){ echo $this->__("Quantity '".$this->escapeHtml($_item->getName())."' invalid! Quantity must: > Min: ".$min_sale_qty.", and < Max: ".$max_sale_qty.", and < Inventory: ".$qtyStock); } ?>"/>
			<?php else: ?>
                <p class="availability out-of-stock"><span><?php echo $this->__('Out of stock') ?></span></p>
            <?php endif; ?>
            </td>
            <?php // endif; ?>
        </tr>
    <?php endforeach; ?>
    <?php else: ?>
       <tr>
           <td colspan="<?php if ($_product->isSaleable()): ?>4<?php else : ?>3<?php endif; ?>"><?php echo $this->__('No options of this product are available.') ?></td>
       </tr>
    <?php endif; ?>
    </tbody>
</table>

<script type="text/javascript">
decorateTable('super-product-table');
</script>